import http from '@/utils/httpRequest'
import systemApi from '@/service/api/system'

export default {
  /**
   * 获取全部菜单信息
   * @returns {Promise<any>}
   */
  getMenuList () {
    return new Promise(function (resolve, reject) {
      http.request(systemApi.sysMenuList).then(res => {
        if (parseInt(res.status) === 200) {
          resolve(res)
        } else {
          reject(res)
        }
      })
    })
  },

  // async getMenuList () {
  //   let result = await http.request(systemApi.sysMenuList)
  //   if (parseInt(result.status) === 200) {
  //     return Promise.resolve(result)
  //   } else {
  //     return Promise.reject(result)
  //   }
  // },
  /**
   * 获取菜单信息
   * @returns {Promise<void>}
   */
  async getMenuInfo (id) {
    let result = await http.request(systemApi.sysMenuInfo + '/' + id)
    return result
  },
  /**
   * 更新菜单
   * @param data
   * @returns {Promise<*>}
   */
  async updateMenuItem (data) {
    let result = await http.request(systemApi.sysMenuUpdate, data, 'POST')
    if (parseInt(result.err_code) === 0) {
      return Promise.resolve(result)
    } else {
      return Promise.reject(result)
    }
  }
}
